//
//  CLNetworkStatus.m
//  Class_IOS
//
//  Created by peter on 14-9-2.
//  Copyright (c) 2014年 qiuyang. All rights reserved.
//

#import "CLNetworkStatus.h"

@implementation CLNetworkStatus
{
}



+ (id)shareNetworkStatus
{
    static id instance = nil;
    static dispatch_once_t once;
    dispatch_once(&once, ^{instance = [[self class] new];});
    return instance;
}


- (id)init
{
    self = [super init];
    if (self) {
        ;
    }
    return self;
}

- (void)reachabilityStatus
{    
    [[AFNetworkReachabilityManager sharedManager] startMonitoring];
    
    [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status){
        NSLog(@"status %d", (int)status);
        switch (status) {
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"AFNetworkReachabilityStatusNotReachable");
                break;
                
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"AFNetworkReachabilityStatusReachableViaWWAN");
                break;
                
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"AFNetworkReachabilityStatusReachableViaWiFi");
                break;
            
            case AFNetworkReachabilityStatusReachableVia2G:
                NSLog(@"AFNetworkReachabilityStatusReachableVia2G");
                break;
                
            case AFNetworkReachabilityStatusReachableVia3G:
                NSLog(@"AFNetworkReachabilityStatusReachableVia3G");
                break;
                
            default:
                break;
        }
        self.currentStatus = status;
        [[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_VIEW_NETWORKSTATUS object:self];
    }];
}

- (void)reachabilityApple
{
    Reachability *reach = [Reachability reachabilityWithHostName:@"www.baidu.com"];
    NSLog(@"%d", (int)[reach currentReachabilityStatus]);
}

- (AFNetworkReachabilityStatus)currentStatus
{
    return _currentStatus;
}

@end
